Skip to content

Conversation

@fussy113
Copy link
Contributor

What

Resolve "EMFILE: too many open files" error caused by watching unnecessary files.

How

  • Change preview command to use fileSystemRepo.getRootPath() instead of config.getItemsRootDir()
  • Make getRootPath() public in FileSystemRepo for external access(Please visit if this is the right approach)
  • Add chokidar ignore pattern to exclude .remote directory from file watching

Why

Solve this discussion

Refs

Resolve "EMFILE: too many open files" error caused by watching unnecessary files.

- Change preview command to use fileSystemRepo.getRootPath() instead of config.getItemsRootDir()
- Make getRootPath() public in FileSystemRepo for external access(Please visit if this is the right approach)
- Add chokidar ignore pattern to exclude .remote directory from file watching
Copilot AI review requested due to automatic review settings November 17, 2025 14:34
@gemini-code-assist
Copy link

Summary of Changes

Hello @fussy113, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical 'too many open files' error that users encountered when running the preview command. The solution involves a targeted optimization of the file watching mechanism. By refactoring the watch path to use a more specific root from the file system repository and explicitly excluding irrelevant directories like .remote, the change significantly reduces the load on the file watcher, ensuring a more stable and efficient preview experience.

Highlights

  • Error Resolution: This pull request resolves the 'EMFILE: too many open files' error that occurred during the preview command, which was caused by watching an excessive number of files.
  • Optimized File Watching: The preview command now uses a more precise watch target by leveraging fileSystemRepo.getRootPath() instead of config.getItemsRootDir(), ensuring only relevant files are monitored.
  • Public API for Root Path: The getRootPath() method in FileSystemRepo has been made public, allowing external modules like the preview command to access the designated root path for file operations.
  • Excluding Unnecessary Directories: The chokidar file watcher has been configured to explicitly ignore the .remote directory, significantly reducing the number of files being watched and preventing resource exhaustion.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the 'EMFILE: too many open files' error by refining the file watching mechanism. The changes to narrow the watch path to the public directory and explicitly ignore the .remote directory are well-targeted. Making getRootPath() public is a reasonable approach to expose the necessary path information from FileSystemRepo, and the addition of a unit test for getRootPath() is a great inclusion. I have one suggestion to improve the platform-independence of the new test case.

it("returns the root path", () => {
const dataRootDir = "./tmp";
const instance = new FileSystemRepo({ dataRootDir });
expect(instance.getRootPath()).toBe(`tmp/public`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a hardcoded path separator / can cause this test to fail on different operating systems, such as Windows. It's best practice to use path.join to construct paths for cross-platform compatibility.

You'll need to add import path from 'node:path'; at the top of the file to use this suggestion.

Suggested change
expect(instance.getRootPath()).toBe(`tmp/public`);
expect(instance.getRootPath()).toBe(path.join("tmp", "public"));

Copilot finished reviewing on behalf of fussy113 November 17, 2025 14:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an "EMFILE: too many open files" error by narrowing the file watching scope from the entire items root directory to just the public subdirectory, and explicitly excluding the .remote directory from being watched.

Key Changes:

  • Changed the preview command to watch only the public/ subdirectory instead of the entire items root directory
  • Made getRootPath() public in FileSystemRepo to enable external access
  • Added chokidar ignore pattern to exclude .remote directory from file watching

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/server/app.ts Added ignore pattern to exclude .remote directory from file watching
src/lib/file-system-repo.ts Changed getRootPath() from private to public visibility
src/lib/file-system-repo.test.ts Added test case for newly public getRootPath() method
src/commands/preview.ts Switched watch path from config.getItemsRootDir() to fileSystemRepo.getRootPath() to narrow scope

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant